
import static java.lang.Character.isDigit;

public class SimpleCalculator {


    private boolean isAlreadyIncremented = false;

    public String[] separateNumbersFromString(String givenString) {

        String[] stringOfNumbers = new String[givenString.length()];
        int x = 0;

        for (int count = 0; count < stringOfNumbers.length; count++)
            stringOfNumbers[count] = "";

        for (int count = 0; count < givenString.length(); count++) {

            if (isDigit(givenString.charAt(count))) {


                stringOfNumbers[x] += givenString.charAt(count);
                isAlreadyIncremented = false;

            } else {
                if (!isAlreadyIncremented) {
                    x++;
                    isAlreadyIncremented = true;

                }
            }
        }
        String[] returnString = new String[x];
        System.arraycopy(stringOfNumbers, 0, returnString, 0, x);
        return returnString;
    }


    public int addOrMultiplyNumbersInAString(String givenString) {

        String[] inputString = separateNumbersFromString(givenString);
        int lengthOfString = givenString.length();
        int result=0;
        if (givenString.charAt(lengthOfString - 1) == '+') {
            for (String s : inputString) {
                result += Integer.parseInt(s);
            }
        }
        else
        if(givenString.charAt(lengthOfString-1)=='*'){
            result=1;
            for(String s : inputString){
                result*=Integer.parseInt(s);
            }
        }
        return result;
    }
}
